/**
 * @file   1100.cpp
 * @author Shuang Hu <hsmath@ubuntu>
 * @date   Sun May  9 00:00:13 2021
 * 
 * @brief  PAT 1100,radix!
 * 
 * 
 */
#include<iostream>
#include<string>
#include<map>
using namespace std;
string s1="tret";
string s2[12]={"jan","feb","mar","apr","may","jun","jly","aug","sep","oct","nov","dec"};
string s3[12]={"tam","hel","maa","huh","tou","kes","hei","elo","syy","lok","mer","jou"};
map<string,int> htable;
map<int,string> invhtable1;
map<int,string> invhtable2;
void changetomars(int d);
void changetoearth(string s);
int main(){
    htable[s1]=0;
    invhtable1[0]=s1;
    invhtable2[0]=s1;
    for(int i=0;i<12;i++){
	htable[s2[i]]=i+1;
	htable[s3[i]]=i+1;
	invhtable1[i+1]=s2[i];
	invhtable2[i+1]=s3[i];
    }
    int datanum;
    cin>>datanum;
    string tmp;
    getline(cin,tmp);
    for(int i=0;i<datanum;i++){
	string s;
	getline(cin,s);
	if(s[0]>='0'&&s[0]<='9'){//earth number
	    int d=stoi(s);
	    changetomars(d);
	}else{
	    changetoearth(s);
	}
    }
}
void changetomars(int d){
    int arr[4];
    int i=0;
    if(d==0){
	cout<<"tret"<<endl;
	return;
    }
    while(d>0){
	arr[i]=d%13;
	d=d/13;
	i++;
    }
    i--;
    if(i==0){
	cout<<invhtable1[arr[0]]<<endl;
    }else{
	cout<<invhtable2[arr[i]];
	for(int j=i-1;j>=1;j--){
	    cout<<" "<<invhtable2[arr[j]];
	}
	if(arr[0]){
	    cout<<" "<<invhtable1[arr[0]]<<endl;
	}else{
	    cout<<endl;
	}
    }
}
void changetoearth(string s){
    int l=s.length();
    int num=0;
    int datanum=l/3;
    string str;
    str=s.substr(0,3);
    num+=htable[str];
    for(int i=1;i<datanum;i++){
	str=s.substr(4*i,3);
	num=num*13;
	num+=htable[str];
    }
    bool flag=false;
    for(int i=0;i<12;i++){
	if(str==s3[i]){
	    flag=true;
	}
    }
    if(flag==true){
	num*=13;
    }
    cout<<num<<endl;
}
